package com.edwin.websitebe.controller;

import com.edwin.websitebe.model.BoxGameType;
import com.edwin.websitebe.model.GameType;
import com.edwin.websitebe.service.BoxGameTypeService;
import com.edwin.websitebe.service.GameTypeMapService;
import com.edwin.websitebe.service.GameTypeService;
import com.edwin.websitebe.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/boxGameType")
@CrossOrigin
public class BoxGameTypeController {

    @Autowired
    private BoxGameTypeService gameTypeService;

    @Autowired
    private GameTypeMapService gameTypeMapService;


    @GetMapping("/list")
    public ResultVO list() {
        List<BoxGameType> list = gameTypeService.list();
        return new ResultVO().success(list);
    }

    @PostMapping("/saveOrUpdate")
    public ResultVO saveOrUpdate(@RequestBody BoxGameType gameType) {
        gameTypeService.saveOrUpdate(gameType);
        return new ResultVO().success();
    }

    @DeleteMapping("/deleteById")
    public ResultVO deleteById(Long id) {
        gameTypeService.removeById(id);
        gameTypeMapService.deleteByTypeId(id);
        return new ResultVO().success();
    }

}
